package day07_14.day10;

public class Board {
    public boolean checkWon(int[][] board) {
        // write code here
        for (int i = 0; i < board.length; i++) {
            for (int j = 0; j < board[i].length; j++) {
                if (i == 1 && j == 1){
                    if (board[i - 1][j - 1] + board[i][j] + board[i + 1][j + 1] == 3 ||
                        board[i - 1][j + 1] + board[i][j] + board[i + 1][j - 1] == 3){
                        return true;
                    }
                }else {
                    if (board[i][j] + left(board , i ,j) + right(board , i , j) == 3 ||
                        board[i][j] + up(board , i ,j) + down(board , i , j) == 3){
                        return true;
                    }
                }
            }
        }
        return false;
    }
    public int right(int[][] board , int i , int j){
        if (j + 1 <= 2){
            return board[i][j + 1];
        }else {
            return 0;
        }
    }
    public int left(int[][] board , int i , int j){
        if (j - 1 >= 0){
            return board[i][j - 1];
        }else {
            return 0;
        }
    }
    public int up(int[][] board , int i , int j){
        if (i + 1 <= 2){
            return board[i + 1][j];
        }else {
            return 0;
        }
    }
    public int down(int[][] board , int i , int j){
        if (i - 1 >= 0){
            return board[i - 1][j];
        }else {
            return 0;
        }
    }

}
